package com.ds.web.controller.applet;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ds.common.annotation.Log;
import com.ds.common.core.controller.BaseController;
import com.ds.common.core.domain.AjaxResult;
import com.ds.common.enums.BusinessType;
import com.ds.applet.domain.MiniBrand;
import com.ds.applet.service.IMiniBrandService;
import com.ds.common.utils.poi.ExcelUtil;
import com.ds.common.core.page.TableDataInfo;

/**
 * 汽车品牌Controller
 *
 * @author liucan
 * @date 2024-04-08
 */
@RestController
@RequestMapping("/applet/brand")
public class MiniBrandController extends BaseController {
    @Resource
    private IMiniBrandService miniBrandService;

    /**
     * 查询汽车品牌列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MiniBrand miniBrand) {
        startPage();
        List<MiniBrand> list = miniBrandService.selectMiniBrandList(miniBrand);
        return getDataTable(list);
    }

    /**
     * 导出汽车品牌列表
     */
    @Log(title = "汽车品牌", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MiniBrand miniBrand) {
        List<MiniBrand> list = miniBrandService.selectMiniBrandList(miniBrand);
        ExcelUtil<MiniBrand> util = new ExcelUtil<MiniBrand>(MiniBrand.class);
        util.exportExcel(response, list, "汽车品牌数据");
    }

    /**
     * 获取汽车品牌详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(miniBrandService.selectMiniBrandById(id));
    }

    /**
     * 新增汽车品牌
     */
    @Log(title = "汽车品牌", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MiniBrand miniBrand) {
        return toAjax(miniBrandService.insertMiniBrand(miniBrand));
    }

    /**
     * 修改汽车品牌
     */
    @Log(title = "汽车品牌", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MiniBrand miniBrand) {
        return toAjax(miniBrandService.updateMiniBrand(miniBrand));
    }

    /**
     * 删除汽车品牌
     */
    @Log(title = "汽车品牌", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(miniBrandService.deleteMiniBrandByIds(ids));
    }
}
